|
1
|
|
|
/** |
|
2
|
|
|
* JavaScript for Bulk Delete Plugin |
|
3
|
|
|
* |
|
4
|
|
|
* http://bulkwp.com |
|
5
|
|
|
* |
|
6
|
|
|
* @author: Sudar <http://sudarmuthu.com> |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/*global BulkWP, postboxes, pagenow*/ |
|
10
|
|
|
jQuery(document).ready(function () { |
|
11
|
|
|
/** |
|
12
|
|
|
* Enable select2 |
|
13
|
|
|
*/ |
|
14
|
|
|
jQuery( '.select2' ).select2(); |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Enable Postbox handling |
|
18
|
|
|
*/ |
|
19
|
|
|
postboxes.add_postbox_toggles(pagenow); |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Toggle the date restrict fields |
|
23
|
|
|
*/ |
|
24
|
|
|
function toggle_date_restrict(el) { |
|
25
|
|
|
if (jQuery("#smbd" + el + "_restrict").is(":checked")) { |
|
26
|
|
|
jQuery("#smbd" + el + "_op").removeAttr('disabled'); |
|
27
|
|
|
jQuery("#smbd" + el + "_days").removeAttr('disabled'); |
|
28
|
|
|
} else { |
|
29
|
|
|
jQuery("#smbd" + el + "_op").attr('disabled', 'true'); |
|
30
|
|
|
jQuery("#smbd" + el + "_days").attr('disabled', 'true'); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Toggle limit restrict fields |
|
36
|
|
|
*/ |
|
37
|
|
|
function toggle_limit_restrict(el) { |
|
38
|
|
|
if (jQuery("#smbd" + el + "_limit").is(":checked")) { |
|
39
|
|
|
jQuery("#smbd" + el + "_limit_to").removeAttr('disabled'); |
|
40
|
|
|
} else { |
|
41
|
|
|
jQuery("#smbd" + el + "_limit_to").attr('disabled', 'true'); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Toggle user login restrict fields |
|
47
|
|
|
*/ |
|
48
|
|
|
function toggle_login_restrict(el) { |
|
49
|
|
|
if (jQuery("#smbd" + el + "_login_restrict").is(":checked")) { |
|
50
|
|
|
jQuery("#smbd" + el + "_login_days").removeAttr('disabled'); |
|
51
|
|
|
} else { |
|
52
|
|
|
jQuery("#smbd" + el + "_login_days").attr('disabled', 'true'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Toggle user registered restrict fields |
|
58
|
|
|
*/ |
|
59
|
|
|
function toggle_registered_restrict(el) { |
|
60
|
|
|
if (jQuery("#smbd" + el + "_registered_restrict").is(":checked")) { |
|
61
|
|
|
jQuery("#smbd" + el + "_registered_days").removeAttr('disabled'); |
|
62
|
|
|
} else { |
|
63
|
|
|
jQuery("#smbd" + el + "_registered_days").attr('disabled', 'true'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
// hide all terms |
|
68
|
|
|
function hideAllTerms() { |
|
69
|
|
|
jQuery('table.terms').hide(); |
|
70
|
|
|
jQuery('input.terms').attr('checked', false); |
|
71
|
|
|
} |
|
72
|
|
|
// call it for the first time |
|
73
|
|
|
hideAllTerms(); |
|
74
|
|
|
|
|
75
|
|
|
// taxonomy click handling |
|
76
|
|
|
jQuery('.custom-tax').change(function () { |
|
77
|
|
|
var $this = jQuery(this), |
|
78
|
|
|
$tax = $this.val(), |
|
79
|
|
|
$terms = jQuery('table.terms_' + $tax); |
|
80
|
|
|
|
|
81
|
|
|
if ($this.is(':checked')) { |
|
82
|
|
|
hideAllTerms(); |
|
83
|
|
|
$terms.show('slow'); |
|
84
|
|
|
} |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
// date time picker |
|
88
|
|
|
jQuery.each(BulkWP.dt_iterators, function (index, value) { |
|
89
|
|
|
// invoke the date time picker |
|
90
|
|
|
jQuery('#smbd' + value + '_cron_start').datetimepicker({ |
|
91
|
|
|
timeFormat: 'HH:mm:ss' |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
jQuery('#smbd' + value + '_restrict').change(function () { |
|
95
|
|
|
toggle_date_restrict(value); |
|
96
|
|
|
}); |
|
97
|
|
|
|
|
98
|
|
|
jQuery('#smbd' + value + '_limit').change(function () { |
|
99
|
|
|
toggle_limit_restrict(value); |
|
100
|
|
|
}); |
|
101
|
|
|
|
|
102
|
|
|
jQuery('#smbd' + value + '_login_restrict').change(function () { |
|
103
|
|
|
toggle_login_restrict(value); |
|
104
|
|
|
}); |
|
105
|
|
|
|
|
106
|
|
|
jQuery('#smbd' + value + '_registered_restrict').change(function () { |
|
107
|
|
|
toggle_registered_restrict(value); |
|
108
|
|
|
}); |
|
109
|
|
|
}); |
|
110
|
|
|
|
|
111
|
|
|
jQuery.each( BulkWP.pro_iterators, function ( index, value) { |
|
112
|
|
|
jQuery('.bd-' + value.replace( '_', '-' ) + '-pro').hide(); |
|
113
|
|
|
jQuery('#smbd_' + value + '_cron_freq, #smbd_' + value + '_cron_start, #smbd_' + value + '_cron').removeAttr('disabled'); |
|
114
|
|
|
} ); |
|
115
|
|
|
|
|
116
|
|
|
// Validate user action |
|
117
|
|
|
jQuery('button[name="bd_action"]').click(function () { |
|
118
|
|
|
var currentButton = jQuery(this).val(), |
|
119
|
|
|
valid = false, |
|
120
|
|
|
msg_key = "deletePostsWarning", |
|
121
|
|
|
error_key = "selectPostOption"; |
|
122
|
|
|
|
|
123
|
|
|
if (currentButton in BulkWP.validators) { |
|
124
|
|
|
valid = BulkWP[BulkWP.validators[currentButton]](this); |
|
125
|
|
|
} else { |
|
126
|
|
|
if (jQuery(this).parent().prev().children('table').find(":checkbox:checked[value!='true']").size() > 0) { // monstrous selector |
|
127
|
|
|
valid = true; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
if (valid) { |
|
132
|
|
|
if (currentButton in BulkWP.pre_action_msg) { |
|
133
|
|
|
msg_key = BulkWP.pre_action_msg[currentButton]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return confirm(BulkWP.msg[msg_key]); |
|
137
|
|
|
} else { |
|
138
|
|
|
if (currentButton in BulkWP.error_msg) { |
|
139
|
|
|
error_key = BulkWP.error_msg[currentButton]; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
alert(BulkWP.msg[error_key]); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
return false; |
|
146
|
|
|
}); |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Validation functions |
|
150
|
|
|
*/ |
|
151
|
|
|
BulkWP.noValidation = function() { |
|
152
|
|
|
return true; |
|
153
|
|
|
}; |
|
154
|
|
|
|
|
155
|
|
|
BulkWP.validateSelect2 = function(that) { |
|
156
|
|
|
if (null !== jQuery(that).parent().prev().children().find(".select2[multiple]").val()) { |
|
157
|
|
|
return true; |
|
158
|
|
|
} else { |
|
159
|
|
|
return false; |
|
160
|
|
|
} |
|
161
|
|
|
}; |
|
162
|
|
|
|
|
163
|
|
|
BulkWP.validateUrl = function(that) { |
|
164
|
|
|
if (jQuery(that).parent().prev().children('table').find("textarea").val() !== '') { |
|
165
|
|
|
return true; |
|
166
|
|
|
} else { |
|
167
|
|
|
return false; |
|
168
|
|
|
} |
|
169
|
|
|
}; |
|
170
|
|
|
|
|
171
|
|
|
BulkWP.validateUserMeta = function() { |
|
172
|
|
|
if (jQuery('#smbd_u_meta_value').val() !== '') { |
|
173
|
|
|
return true; |
|
174
|
|
|
} else { |
|
175
|
|
|
return false; |
|
176
|
|
|
} |
|
177
|
|
|
}; |
|
178
|
|
|
}); |
|
179
|
|
|
|